package cc.atliberty.creating.builder.carmodel;

import java.util.ArrayList;
import java.util.Random;

/**
 * @Author 元宵
 * @url www.atliberty.cc
 * @Date 2023-10-30 19:25
 * @description: 客户端
 */
public class Client {
    public static void main(String[] args) {
        String[] strs = {"BMWModel", "BenzModel"};
        String[] actions = {"start", "stop", "alarm", "enginBoom"};
        ArrayList<String> sequence = new ArrayList<>();
        Random random = new Random();
        int ri = random.nextInt(actions.length);
        System.out.println(ri);
        for (String str : strs) {
            try {
                CarModel carModel = (CarModel) Class.forName(Client.class.getPackageName() + "." + str).newInstance();
                sequence.clear();
                for (int i = 0; i < actions.length; i++) {
                    sequence.add(actions[ri++]);
                    if (ri >= actions.length) {
                        ri = 0;
                    }
                }
                carModel.setSequence(sequence);
                carModel.run();
            } catch (Exception e) {
                e.printStackTrace();
            } 
        }
    }
}
